// components/showView/recruit/recruit.js
let network = require('../../../utils/requestManager.js')
let utils = require('../../../utils/util.js')
Component({
  /**
   * 组件的初始数据
   */
  data: {
    list: [],
    posititon_list: [],
    money: '',
    isBlank:true,
    recruit_data: {
      title: ""
    }
  },

  /**
   * 开启多组件支持
   * **/
  options: {
    multipleSlots: true //启用多slot支持
  },

  /**
   * 组件的属性列表
   */
  properties: {
    //通过page传入数据
    recruitData: { //属性名称，在page中要使用连字符方法
      type: Object, //属性类型
      value: "", //初始值
      observer: function(newVal, oldVal, changePath) { //属性改变时执行函数
        console.log(newVal);
        this.setData({

        })
      }
    }
  },

  /**
   * 生命周期函数，可以为函数，或一个在methods段中定义的方法名
   * **/
  lifetimes: {
    // 
    attached: function() {

    },
    moved: function() {},
    detached: function() {},

  },

  /**
   * 组件所在页面的生命周期函数
   * **/
  pageLifetimes: {
    show: function() {
      detailPage(this)
      console.log("000")
      //triggerEvent:参数一为绑定组件的函数名，参数二为传递的数据
      this.triggerEvent("recruitCopmonent", {
        recruitData: this.data.recruit_data.title
      })
    },
  },
  enterToDetail: function(e) {

    wx.navigateTo({
      url: 'pages/showView/recruit/yingPinRecord/detailPosition',
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })

  },


  /**
   * 组件的方法列表
   */
  methods: {
    enterToDetail: function(e) {
      var index = e.currentTarget.dataset.index
      console.log('---------------------9999--------------------')
      console.log(index)
      let id=this.data.list[index].id
      wx.navigateTo({
        url: '../../pages/showView/recruit/detailPosition?ID='+id,
        success: function(res) {},
        fail: function(res) {},
        complete: function(res) {},
      })

    },
  }
})

function detailPage(that) {
  let params = network.shopParams()
  let url = 'recruitment/info/list'
  console.log(url)
  console.log(params)
  network.getRequest(url, params, function(res) {
    console.log("----------------------------------shop---------------------")
    console.log(res)
    let result = res.results
    var results2 = []
    if(result.length>0){
      that.setData({
        isBlank: false
      })
    }
    for (let i = 0; i < result.length; i++) {
      var dic = result[i]
      // let welfareList = dic.welfare.split(',')
      // dic['welfare'] = welfareList
      // let welfareList=[]
      // for(let i=0;i<dic.welfare.length;i++){
      //   let name=dic.welfare.name
      //   welfareList.push(name)
      // }   

      dic['welfare']= JSON.parse(dic.welfare)
      let create_time = dic.create_time;
      create_time = utils.formatUTCDate(create_time);
      let create_time1= create_time.split(' ')[0]
      dic['create_time'] = create_time1
      results2.push(dic)
    }
    console.log('11111-------------------111111')
    console.log(results2)
    that.setData({
      list: results2
    })


  })


}